Namespace RSS
    Public Class clRssFeed
        Dim _version As String
        Dim _canal As RSS.iRssCanal

        Public Sub New(ByVal titulo As String, ByVal link As String, ByVal descripcion As String, ByVal fechaPublicacion As DateTime, Optional ByVal ttl As Integer = -1, Optional ByVal version As String = "2.0")
            _version = version
            _canal = New RSS.clRssCanal(titulo, link, descripcion)
            _canal.ttl = ttl
        End Sub
        Public Sub New(ByVal canal As RSS.iRssCanal, Optional ByVal version As String = "2.0")
            _version = version
            _canal = canal
        End Sub

        Public Property Canal() As RSS.iRssCanal
            Get
                Return _canal
            End Get
            Set(ByVal value As RSS.iRssCanal)
                _canal = value
            End Set
        End Property

        Public Property version() As String
            Get
                Return _version
            End Get
            Set(ByVal value As String)
                _version = value
            End Set
        End Property

        Public Function generarFeed() As String
            Dim sw As New IO.StringWriter
            Dim writer As New Xml.XmlTextWriter(sw)
            writer.WriteStartElement("rss")
            writer.WriteAttributeString("version", "2.0")
            With writer
                .WriteStartElement("channel")
                .WriteElementString("title", Canal.titulo)
                .WriteElementString("link", Canal.link)
                .WriteElementString("description", Canal.descripcion)
                .WriteElementString("pubDate", RSS.GetRFC822Date(Canal.fechaPublicacion))
                If Canal.ttl > -1 Then .WriteElementString("ttl", Canal.ttl.ToString)
                Dim i As RSS.iRssItem
                For Each i In Canal.getItems
                    .WriteStartElement("item")
                    .WriteElementString("title", i.titulo)
                    .WriteElementString("link", i.link)
                    .WriteElementString("description", i.descripcion)
                    .WriteElementString("pubDate", RSS.GetRFC822Date(i.fechaPublicacion))
                    .WriteEndElement()
                Next
                .WriteEndElement()
            End With
            writer.WriteEndElement()
            Dim aux As String = sw.ToString
            writer.Close()
            Return aux
        End Function
    End Class
End Namespace

